package yxy.game.pm2.command.soul;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.Soul;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.HeroMessage;
import yxy.game.pm2.module.hero.SoulHandle;

/** 魂玉 魂玉重铸信息 */
@MessageType(proto = Command.SoulRecoinInfo, classtype = HeroMessage.SoulRecoinInfoRequest.class)
public class CMD_SoulRecoinInfo extends Command<HeroMessage.SoulRecoinInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, HeroMessage.SoulRecoinInfoRequest request) {
		String playerCode = messageSource.getTag();
		String soulCode = request.getCode();

		HeroMessage.SoulRecoinInfoResponse.Builder response = HeroMessage.SoulRecoinInfoResponse.newBuilder();

		Soul soul = Soul.get(playerCode, soulCode);
		if (soul == null) {
			send(messageSource, response, Result.ParamError);
			return;
		}

		response.setSoul(new SoulHandle().packSoul(soul));
		if (soul.getRePropertyIds() != null) {
			response.addAllReproperty(soul.getRePropertyIds());
		}
		if (soul.getReSkillIds() != null) {
			response.addAllReskill(soul.getReSkillIds());
		}

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, HeroMessage.SoulRecoinInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}